﻿using BLL;
using InventoryMIS2019.conn;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace InventoryMIS2019
{
    public partial class _ExamPurchaseBill : InventoryMIS2019.Templates.BasePurchaseBillForm
    {
        List<string> PendingIDList;
        ExamPurchaseBillBLL bl;
        string opera;
        public _ExamPurchaseBill()
        {
            InitializeComponent();
            bl = new ExamPurchaseBillBLL();
            lbPurchaseBill.Enabled = true;
        }
        private List<string> GetInStockPurchaseBill()
        {
            PendingIDList = bl.GetInStockPurchaseBill();
            return PendingIDList;
        }
        private void GetValues()
        {
            bo = new PurchaseBill();
            bo.PurchaseBillID = txtPurchaseID.Text.Trim();
            bo.Examiner = "800001";
            bo.Memo = txtMemo.Text;
        }
        private void bntYesWarehousing_Click(object sender, EventArgs e)
        {
            GetValues();
            opera = "YES";
        }

        private void bntNoWarehousing_Click(object sender, EventArgs e)
        {
            GetValues();
            opera = "NO";
        }

        private void bntNO_Click(object sender, EventArgs e)
        {
            bntYesWarehousing.Enabled = bntNoWarehousing.Enabled = true;
            ClearControls.ClearControl(this);
            lbPurchaseBill.DataSource = GetInStockPurchaseBill();//更新ListBox控件数据源
        }

        private void btnYES_Click(object sender, EventArgs e)
        {
            if (opera == "YES")
            {
                if (bl.AgreeInStock(bo))
                {
                    MessageBox.Show("订单入库通过", "系统提示");
                    lbPurchaseBill.DataSource = GetInStockPurchaseBill();
                }
            }
            if (opera == "NO")
            {
                if (bl.NOAgreeInStock(bo))
                {
                    MessageBox.Show("订单入库不通过", "系统提示");
                    lbPurchaseBill.DataSource = GetInStockPurchaseBill();
                }
                bntYesWarehousing.Enabled = bntNoWarehousing.Enabled = true;
            }
        }

        private void _ExamPurchaseBill_VisibleChanged(object sender, EventArgs e)
        {
            if (GetInStockPurchaseBill().Count == 0)
            {
                lbPurchaseBill.DataSource = null;
            }
            else
            {
                lbPurchaseBill.DataSource = GetInStockPurchaseBill();
                lbPurchaseBill.SelectedIndex = -1;
            }
        }
    }
}
